<?php
namespace MLM\Controller;

use Zend\View\Model\ViewModel;
use Zend\Authentication\Result;
use Zend\Authentication\AuthenticationService;

class IndexController extends \MLM\Model\Generic\Controller {
    
    public function indexAction() {
        $identity = $this->hasSession();
        
        if ($identity->member_type_id == 4)
            $this->layout('layout/admin');
        else
            $this->layout('layout/member');

        
        return new ViewModel();
    }
	
    public function jqgridAction() {
        $view = new ViewModel();
        $view->setTerminal(true);
        return $view;
    }

    private function hasSession() {
        $auth = new AuthenticationService();

        $identity = $auth->getIdentity();
		//print_r($identity);
        if (!$auth->hasIdentity()) {
			//echo "gak ada session";
            return $this->redirect()->toRoute('application/default', array('controller' => 'Index', 'action' => 'login'));
        } else {
            return $auth->getIdentity();
        }
    }

}
